package observer;

import java.util.List;

import javax.swing.text.html.HTMLDocument.Iterator;

public class Senzor implements Subject{
	private List<Observer> obs=new LinkedList<Observer>();
	private int valCurenta = 0;
	
	//adauga un Observer
	public void addObserver(Observer o){
		obs.add(o);
	}
	
	//sterge un observer
	public void removeObserver(Observer o){
		obs.remove(o);
	}
	
	//notifica observerii
	pubilc void notifyObserver(){
		Iterator i=obs.iterator();
		while(i.hasNext()){
			Observer o=(Observer) i.next();
			o.upDate(this);
		}
	}
	
	//genereaza un numar aleator
	public void generare(){
		Random serieRandom=new Random();
		valCurenta=serieRandom.nextInt(80);
		notifyObserver();
	}
	
	//returneaza valoarea curenta
	public int getVal(){
		return valCurenta;
	}

}
